package com.weimei.conversionTreasure.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import com.google.android.material.tabs.TabLayout;
import com.weimei.conversionTreasure.R;
import com.weimei.conversionTreasure.app.AppViewModelFactory;
import com.weimei.conversionTreasure.databinding.ActivityDetailRecordBinding;
import com.weimei.conversionTreasure.viewModel.AddRecordVM;
import com.weimei.conversionTreasure.viewModel.DRVM;

import me.goldze.mvvmhabit.base.BaseActivity;
import me.tatarka.bindingcollectionadapter2.BR;

public class DetailRecordActivity extends BaseActivity<ActivityDetailRecordBinding, DRVM> {


    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_detail_record;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    String flag;
    @Override
    public void initParam() {
        super.initParam();
        flag = getIntent().getStringExtra("flag");
    }

    @Override
    public DRVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, (ViewModelProvider.Factory) factory).get(DRVM.class);
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.setActivity(this);
        binding.tab.addTab(binding.tab.newTab().setText("发酵提醒"));
        binding.tab.addTab(binding.tab.newTab().setText("泡粮提醒"));

        if (flag.equals("pl")){
            binding.tab.getTabAt(1).select();
            viewModel.type.set("1");
        }else {
            binding.tab.getTabAt(0).select();
            viewModel.type.set("0");
        }

        binding.tab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewModel.type.set(""+tab.getPosition());
                viewModel.onResume();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }
}